{% extends "layout/home_base.html" %}
{% block home_content %}
<div class="section">
  <div class="section__header">
    <h1 class="section__title">{{ _('My Domains') }}</h1>
    <div class="section__tools">
    {% if handler.has_priv(vj4.model.builtin.PRIV_CREATE_DOMAIN) %}
      <a class="primary rounded button" href="{{ reverse_url('home_domain_create') }}"><span class="icon icon-add"></span> {{ _('Create Domain') }}</a>
    {% endif %}
      <a class="tool-button" href="{{ reverse_url('wiki_help') }}#domain"><span class="icon icon-help"></span> {{ _('What\'s domain?') }}</a>
    </div>
  </div>
{% if pending_ddocs|length > 0 %}
  <div class="section__body">
    <blockquote class="note">
      {{ _('You have uncompleted domain creation operation. You can click "Continue" to finish the creation.') }}
    </blockquote>
  </div>
{% endif %}
  <div class="section__body no-padding">
    <table class="data-table">
      <colgroup>
        <col class="col--icon">
        <col class="col--name">
        <col class="col--role">
        <col class="col--action">
      </colgroup>
      <thead>
        <tr>
          <th class="col--icon">&nbsp;</th>
          <th class="col--name">{{ _('Name') }} ({{ _('ID') }})</th>
          <th class="col--role">{{ _('My Role') }}</th>
          <th class="col--action">{{ _('Action') }}</th>
        </tr>
      </thead>
      <tbody>
      {% for ddoc in pending_ddocs %}
        <tr>
          <td class="col--icon">
            <img src="{{ ddoc['gravatar']|gravatar_url }}" width="32" height="32">
          </td>
          <td class="col--name">
            <span class="text-red">{{ _('Uncompleted') }}</span>: {{ ddoc['name'] }} ({{ ddoc['_id'] }})
          </td>
          <td class="col--role">
            --
          </td>
          <td class="col--action"><form method="post">
            <input type="hidden" name="domain_id" value="{{ ddoc['_id'] }}">
            <input type="hidden" name="csrf_token" value="{{ handler.csrf_token }}">
            <button type="submit" class="typo-a">{{ _('Continue') }}</button>
          </form></td>
        </tr>
      {% endfor %}
      {% for ddoc in vj4.model.builtin.DOMAINS %}
        <tr>
          <td class="col--icon">
            <img src="{{ ddoc['gravatar']|gravatar_url }}" width="32" height="32">
          </td>
          <td class="col--name">
            <span data-tooltip="{{ _('This is a built-in domain that every user is in.') }}">{{ ddoc['name'] }} ({{ ddoc['_id'] }})</span>
          </td>
          <td class="col--role">
            {{ dudict.get(ddoc['_id'], {})['role']|default(vj4.model.builtin.ROLE_DEFAULT) }}
          </td>
          <td class="col--action">
            <a class="typo-a" href="{{ reverse_url('domain_main', domain_id=ddoc['_id']) }}">{{ _('Visit') }}</a>
          {% if can_manage[ddoc['_id']] %}
            · <a class="typo-a" href="{{ reverse_url('domain_manage', domain_id=ddoc['_id']) }}">{{ _('Manage') }}</a>
          {% endif %}
          </td>
        </tr>
      {% endfor %}
      {% for ddoc in ddocs %}
      {% if not ddoc['pending'] %}
        <tr>
          <td class="col--icon">
            <img src="{{ ddoc['gravatar']|gravatar_url }}" width="32" height="32">
          </td>
          <td class="col--name">
            {{ ddoc['name'] }} ({{ ddoc['_id'] }})
          </td>
          <td class="col--role">
            {{ dudict.get(ddoc['_id'], {})['role']|default(vj4.model.builtin.ROLE_DEFAULT) }}
          </td>
          <td class="col--action">
            <a class="typo-a" href="{{ reverse_url('domain_main', domain_id=ddoc['_id']) }}">{{ _('Visit') }}</a>
          {% if can_manage[ddoc['_id']] %}
            · <a class="typo-a" href="{{ reverse_url('domain_manage', domain_id=ddoc['_id']) }}">{{ _('Manage') }}</a>
          {% endif %}
          </td>
        </tr>
      {% endif %}
      {% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
